Plant seedling classification

Context

Context: The Aarhus University Signal Processing group, in collaboration with University of Southern Denmark, hasrecently released a dataset containing images of unique plants belonging to 12 species at several growth stages. Can a weed be differentiated from a crop seedling?T he ability to do so effectively can mean better crop yields and better stewardship of the environment. The goal of the project is to create a classifier capable of determining a plant's species from a photo.

List of Species

Data Description:

Dataset

The data consists of Image file and label csv for 4750 records

Problem Statement

The goal of the project is to create a classifier capable of determining a plant's species from a photo

Importing the libraries

Reading the Training Data

Printing image of each seedling

Data Preprocessing

Normalizing pixel values

Exploratory Data Analysis

The above plot shows that the distribution of seedlings in the dataset is imbalanced,

Applying Gaussian blurring

Printing the images after normalization and Gaussian blurring

Finding the mean images for each class of tumor:

Splitting data between training and testing

One hot encoding

Model Building

We will be using convoluation neural netwrok for model building:

Convolutional Neural Network (CNN)

Model 1: CNN with Dropout

Convolutional Neural Network (CNN)

Model 2: CNN with Dropout after Convolution and having two Dense layers with 16 & 32 units respectively

Since CNN Model 1 gives an ok test accuracy and appears to be slighlty overfitting on the training dataset, let's use CNN Model 2, which has a different architecture that should generalize well and not overfit.

The accuracy of this model is 73% on training set. This model unfortunately does not have as good training accuracy, as compared to model1 and it appears to be underfitting on the training dataset. That means we need to increase the complexity of the model in our next attempt.

Convolutional Neural Network (CNN)

Model 3: CNN with Dropout after Convolution and having two Dense layers with 512 & 256 Units respectively

*The accuracy on the training set is a bit better than model1. This model has the best training accuracy.

Plotting the Train & Test Accuracy

CNN Model 1

CNN Model 2

CNN Model 3

Model Evaluation

CNN Model 1

CNN Model 2

CNN Model 3

Even though Model 3 has more accuracy on training set but its accuracy on testing data is not good. It is overfitting. Model1 is coming out as the best model. It is an imbalanced dataset.So we are more concerned with Precision and Recall. Since these two metrics are both quite important in this scenario, we will also check the F1 score to try to achieve a good balance between Precision and Recall.

Plotting the confusion matrix for the two best models

As we can see, Model 1 and Model 3 seem to be generalizing well because they both have a good Holdout set Accuracy. Let us compute the confusion matrix for these two models to understand the distribution of True Positives, False Positives, False Negatives and True Negatives.

CNN Model 1

CNN Model 3

The above two confusion matrices show that the models seem to be working well. Let's calculate the F1 score (the harmonic mean of precision and recall), which is used as an evaluation metric for imbalanced datasets.

Classification Report for each class

The order of printing the above metrices for each class is as follows:

CNN Model 1

CNN Model 3

Model 1 (Best) Observation

As we see from the precision for each class, the Common wheat classifier has the highest precision. But here, we are more concerned about the case where a seedling is wrongly classified as belonging to the weed category (False Negative).

18% of Small flowered crainesbill, 17% belonging to Shepherd's Purse and 11% of sugar beet are not identified correctly, and the model predicts that they are weeds* - which shows that our model does not do well in identifying Small Flowered crainesbill, Shepherd's Purse and sugar beet. But it is works well for the other seedlings, where it does not classify them as weeds

Weighted F-Score

Model 1

Model 3

Model 1 CNN with droupout has a better F1 score.

Conclusion

There is still scope for improvement in the test accuracy and F1 score of the CNN model chosen here. Different architectures can be built and hyperparamter tuning can be performed to obtain a better plant seedlings classifications.

Some of the techniques which could be used for further improving the performance of the model are